#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

class SegmentTree {
public:
    struct TreeNode {
        int from, to, sum;
        int lazy_tag;
        TreeNode(int f, int t, int s) {
            from = f;
            to = t;
            sum = s;
            lazy_tag = 0;
        };
    };
    const int maxnLen = 100000;
    int numslen;

    vector<TreeNode> tree;

    SegmentTree(int rootFrom, int rootTo) : tree(4 * (rootTo - rootFrom + 1), TreeNode(0, 0, 0)) {
        numslen = rootTo - rootFrom + 1;
    }

    void BuildTree(int nodeIndex, int startInd, int endInd) {
        if (startInd == endInd) {
            tree[nodeIndex] = TreeNode(startInd, endInd, 1);
            return;
        }
        int leftchild = nodeIndex * 2;
        int rightchild = nodeIndex * 2 + 1;
        int mid = (startInd + endInd) / 2;
        BuildTree(leftchild, startInd, mid);
        BuildTree(rightchild, mid + 1, endInd);
        tree[nodeIndex].sum = tree[leftchild].sum + tree[rightchild].sum;
        tree[nodeIndex].from = startInd;
        tree[nodeIndex].to = endInd;
        return;
    }

    void Update(int i) {
        int left = i * 2, right = i * 2 + 1;
        if (tree[i].lazy_tag != 0) {
            tree[left].sum = 0;
            tree[right].sum = 0;
            tree[left].lazy_tag = 1;
            tree[right].lazy_tag = 1;
            tree[i].lazy_tag = 0;
        }
        return;
    }

    int Visit(int i, int start, int end) {
        if (start > end)
            return 0;

        int mid = (tree[i].from + tree[i].to) / 2;
        int left = i * 2, right = i * 2 + 1;
        int LeftSum, RightSum;

        if (tree[i].from == start && tree[i].to == end) {  // range was covered precisely by this node
            return tree[i].sum;
        } else if (tree[i].from <= start && end <= mid) {  // range was covered by the left side
            Update(i);
            return Visit(left, start, end);
        } else if (mid > start && end <= tree[i].to) {  // range was covered by the right side
            Update(i);
            return Visit(right, start, end);
        } else {  // range was covered by this node, and have intersections on both the left and right sides
            Update(i);
            LeftSum = Visit(i * 2, start, mid);
            RightSum = Visit(i * 2 + 1, mid + 1, end);
            return LeftSum + RightSum;
        }
    }

    void Modify(int i, int start, int end, int val) {
        if (start > end)
            return;
        int mid = (tree[i].from + tree[i].to) / 2;
        int left = i * 2, right = i * 2 + 1;

        if (tree[i].from == start && tree[i].to == end) {
            tree[i].sum = 0;
            tree[i].lazy_tag = 1;
            return;
        } else if (tree[i].from <= start && end <= mid) {
            Update(i);
            Modify(left, start, end, val);
        } else if (mid < start && end <= tree[i].to) {
            Update(i);
            Modify(right, start, end, val);
        } else {
            Update(i);
            Modify(left, start, mid, val);
            Modify(right, mid + 1, end, val);
        }
        tree[i].sum = tree[left].sum + tree[right].sum;
        return;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    SegmentTree segTree(0, n);
    segTree.BuildTree(1, 0, n);
    for (int i = 0; i < m; i++) {
        int f, t;
        cin >> f >> t;
        segTree.Modify(1, f, t, -1);
    }
    cout << segTree.Visit(1, 0, n);
}